<?= $this->Html->css('multi-inputs', null, array('inline'=>false)) ?>
<?= $this->Html->script('multi-inputs.asset', array('inline'=>false)) ?>

<p class="entity-table">
    <?= $this->Html->link("&laquo; nazad", "/locations", array( 'escape' => false ))?>
    
    <span class="actions visible form button-set">
    <? if (!empty($data['Location']['id'])): ?>
    <? $locationId = $data['Location']['id'] ?>
    
        <?= $this->Form->button('Kreiraj kampanju', array(
            'type'    => 'button',
            'onclick' => "location.href='/campaigns/create/?location={$locationId}'"
        )) ?><?= $this->Form->button('Rezerviši', array(
            'type'    => 'button',
            'onclick' => "location.href='/location_reservations/create/?location={$locationId}'"
        )) ?><?= $this->Form->button('Obriši', array(
            'class'   => 'delete',
            'onclick' => "if (confirm('Da li želite da obrišete lokaciju?')){location.href = '/locations/remove/{$locationId}'}"
        ))?>
    <? endif ?>
    </span>
</p>
<?= $this->Form->create('Location', array('url' => '/locations/save', 'enctype'=>'multipart/form-data')) ?>

    <?= $this->Form->hidden('id', array( 'value' => (int)@$data['Location']['id'])) ?>

	<div class="right" style="margin-left:10px">
		<?= $this->Form->hidden('latlng', array('value' => @$data['Location']['latlng'], 'class'=>'latlng')) ?>
		
		<?= $this->Form->label('lat', 'Širina:', array('class'=>'auto')) ?>
		<?= $this->Form->text('lat', array('class' => 'lat small')) ?>
		<?= $this->Form->label('lng', 'Dužina:', array('class'=>'auto')) ?>
		<?= $this->Form->text('lng', array('class' => 'lng small')) ?>
		
		<?= $this->element('map', array(
		'width'  => 400,
		'height' => 400,
		'latlng' => @$data['Location']['latlng']
	)) ?></div>

    <p><?= $this->Form->label('name', 'Naziv:') ?>
    <?= $this->Form->text('name', array( 'value' => @$data['Location']['name'])) ?>
    <?= $this->App->formError('name') ?></p>
    
    <p><?= $this->Form->label('address', 'Adresa:') ?>
    <?= $this->Form->text('address', array( 'value' => @$data['Location']['address'])) ?>
    <?= $this->App->formError('address') ?></p>
    
    <?php
        if (empty($data['AdType'])) {
            $data['AdType'] = array(array());
        }
    ?>
    
    <p class="left"><?= $this->Form->label('ad_type_id', 'Reklame:', array('class'=>'left')) ?>
        <span class="multi-inputs left">
        <? foreach ($data['AdType'] as $k=>$adType): ?>
            <span class="multi-input">
                <?= $this->Form->select("LocationsAdType.{$k}.ad_type_id", $ad_types, array(
                    'value' => @$adType['id'],
                    'empty' => false
                )) ?>
                <?= $this->Form->text("LocationsAdType.{$k}.width", array(
                    'value' => @$adType['LocationsAdType']['width'], 'class'=>'number'
                )) ?> X
                <?= $this->Form->text("LocationsAdType.{$k}.height", array(
                    'value' => @$adType['LocationsAdType']['height'], 'class'=>'number'
                )) ?> <?= LENGTH_SYM ?>
            </span>
        <? endforeach ?>
        </span>
    </p><br clear="left">
    
    <p><?= $this->Form->label('rent_price', 'Cena zakupa:') ?>
    <?= $this->Form->text('rent_price', array( 'value' => @$data['Location']['rent_price'], 'class'=>'price')) ?><?= CURRENCY_SYM ?>
    <?= $this->App->formError('rent_price') ?>
    <? if(@$data['Location']['id']): ?>
        
        <?= $this->Form->label('price_production', 'Cena izrade:') ?>
        <strong><?= currency_format($data['Location']['price']) ?><?= CURRENCY_SYM ?></strong>
        
        <?= $this->Form->label('price_total', 'Ukupno:') ?> 
        <strong><u><?= currency_format($data['Location']['price'] + @$data['Location']['rent_price']) ?><?= CURRENCY_SYM ?></u></strong>
    <? endif ?>
    </p>
    
    <fieldset>
    	<legend>Fotografije</legend>
    	<?= $this->element('photo_list', array(
    		'name' => 'LocationImage',
    		'data' => @$data['LocationImage'],
    		'path' => 'locations/' . @$data['Location']['id'] . '/%s'
		)) ?>
    </fieldset>
    
    <?= $this->Form->button('Sačuvaj') ?>
<?= $this->Form->end() ?>
